package com.corffen.algorithm.stack;

import java.util.Stack;

public class MinStack {


    private Stack<Integer> mStack = new Stack<>();
    private Stack<Integer> mMinStack = new Stack<>();

    public void push(int number) {
        mStack.push(number);
        if (mMinStack.isEmpty()) {
            mMinStack.push(number);
        } else {
            mMinStack.push(Math.min(number, mMinStack.peek()));
        }
    }

    public int pop() {
        mMinStack.pop();
        return mStack.pop();
    }

    /**
     * 用于查询栈中最小的元素
     *
     * @return
     */
    public int peek() {
        return mMinStack.peek();
    }
}
